package com.hhkj.study.admin.resource.service.extend.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.google.common.collect.Lists;
import com.hhkj.study.admin.course.enums.CourseAssocResourceTypeEnum;
import com.hhkj.study.admin.resource.entity.ResourceCourseBase;
import com.hhkj.study.admin.resource.entity.ResourceCourseOffline;
import com.hhkj.study.admin.resource.model.podo.ResourceCourseOfflineDo;
import com.hhkj.study.admin.resource.model.podo.ResourceCourseOfflinePo;
import com.hhkj.study.admin.resource.service.base.ResourceCourseOfflineService;
import com.hhkj.study.admin.resource.service.extend.ResourceCourseBaseExtendService;
import com.hhkj.study.admin.resource.service.extend.ResourceCourseOfflineExtendService;
import com.ruoyi.common.base.biz.service.extend.BaseExtendServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

/**
*
* @author SERVER
* @since 2024-09-06
*/
@Service
public class ResourceCourseOfflineExtendServiceImpl extends BaseExtendServiceImpl<ResourceCourseOffline, ResourceCourseOfflineDo, ResourceCourseOfflinePo, ResourceCourseOfflineService>
        implements ResourceCourseOfflineExtendService, ResourceCourseBaseExtendService {

    @Override
    public ResourceCourseOffline getByNameCourseType(String name, Long courseType) {
        LambdaQueryWrapper<ResourceCourseOffline> offlineQueryWrapper = new LambdaQueryWrapper<>();
        offlineQueryWrapper.eq(ResourceCourseOffline::getName, name).eq(ResourceCourseOffline::getCourseType, courseType).last("LIMIT 1");
        return this.getService().getOne(offlineQueryWrapper);
    }

    @Override
    public CourseAssocResourceTypeEnum getCourseResourceTypeEnum() {
        return CourseAssocResourceTypeEnum.OFFLINE;
    }

    @Override
    public List<ResourceCourseOfflinePo> listByIdList(Collection<Long> idList) {
        if (CollectionUtil.isEmpty(idList)) {
            return Lists.newArrayList();
        }
        ResourceCourseOfflineDo resourceCourseOfflineDo = new ResourceCourseOfflineDo();
        resourceCourseOfflineDo.setIdList(Lists.newArrayList(idList));
        return this.getService().listPoByDo(resourceCourseOfflineDo);
    }

    @Override
    public List<? extends ResourceCourseBase> getResouceListByIdList(Collection<? extends Serializable> idList, List<? extends ResourceCourseBase> resourceList) {
        if (CollectionUtil.isEmpty(idList) || CollectionUtil.isEmpty(resourceList)) {
            return Lists.newArrayList();
        }
        List<ResourceCourseOffline> resourceCourseList =  BeanUtil.copyToList(resourceList, ResourceCourseOffline.class);
        return resourceCourseList.stream().filter(e -> idList.contains(e.getId())).collect(Collectors.toList());
    }
}
